package com.qding.park.manager.app.queue.handle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.qding.park.common.core.exceptions.BaseException;
import com.qding.park.common.core.redis.SerializeUtils;
import com.qding.park.manager.facade.queue.service.BusinessFacade;
import com.qding.park.manager.facade.queue.service.EventWriteBack;
import com.qding.park.manager.pojo.TbMonthRent;
import com.qding.park.manager.pojo.queue.QueueMsg;

/**
 * @ClassName InviteTimeOutHandle
 * @Description TODO(月租续费支付完成消息)
 * @author Administrator
 * @Date 2016年9月17日 下午4:04:55
 * @version 1.0.0
 */
@Component("monthPayedHandle")
public class MonthPayedHandle extends AbstractOrderHandle {

	/**
	 * @Field @inviteFacade : TODO(邀请单核心业务)
	 */
	@Autowired
	private BusinessFacade businessFacade;

	@Autowired
	private EventWriteBack eventWriteBack;

	@Override
	void actualHandle(QueueMsg msg) throws BaseException {
		JSONObject data = (JSONObject) msg.getData();
		TbMonthRent tbMonthRent = SerializeUtils.unSerialize(data.toJSONString(), TbMonthRent.class);
		businessFacade.monthPayedAfter(tbMonthRent);
		
		// 事件回写 月租缴费单完成之后 的回写日志 此数据用于报表分析
		eventWriteBack.MonthPayComplete(tbMonthRent);
	}

	@Override
	boolean failDiscardRollBacK(QueueMsg msg) {
		_log.error("邀请单超时回滚:" + msg);
		return true;
//		try {
//			JSONObject data = (JSONObject) msg.getData();
//			TbMonthRent tbMonthRent = SerializeUtils.unSerialize(data.toJSONString(), TbMonthRent.class);
//			payFeeFacade.monthRentpayedIssuedFailRollBack(tbMonthRent);
//			return true;
//		} catch (Throwable e) {
//			return false;
//		}

	}

}
